package com.xxgc.eow.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.xxgc.eow.generator.CodeGenerator;
import com.xxgc.eow.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: ExhibitionOfWorks
 * @description: 代码生成接口
 * @author: Mr.Abel SJY
 * @Email thanksjava@qq.com
 * @create: 2023-05-07 21:29
 **/
@ApiSort(99999)
@Tag(name = "逆向工程接口")
@RestController
@RequestMapping("/code")
public class CodeGenerationController {

    @Autowired
    private CodeGenerator codeGenerator;

    @ApiOperationSupport(author = "石老师 thanksjava@qq.com")
    @Operation(summary = "代码生成(仅在开发环境使用)", description = "通过数据库表名逆向生成业务代码,仅在开发环境使用!!!.尽量不要生成controller层")
    @Parameters({
            @Parameter(name = "tableName",description = "数据库表名",required = true,in=ParameterIn.QUERY),
            @Parameter(name = "noController",description = "不生成controller层",example="true",required = true,in=ParameterIn.QUERY)
    })
    @PostMapping("/login")
    public Result userLogin(@RequestParam("tableName") String tableName,
                            @RequestParam("noController") boolean noController){
        codeGenerator.generator(tableName,noController);
        return Result.okMsg("生成完成");
    }

}
